package com.loe.test

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import com.loe.scan.ScanFragment
import kotlinx.android.synthetic.main.activity_test_frag.*

class TestFragActivity : AppCompatActivity()
{
    private val frag by lazy { supportFragmentManager.findFragmentByTag("frag") as ScanFragment }

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            val window = window
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
            window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = Color.TRANSPARENT
            window.navigationBarColor = -0x1000000
        }
        setContentView(R.layout.activity_test_frag)


        frag.setOnResult()
        {
            if(it.isNotEmpty())
            {
                frag.isScanning = false
                Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
                Handler(mainLooper).postDelayed({ frag.isScanning = true }, 3000)
            }
        }
        buttonLight.setOnClickListener { frag.clickLight(it) }
        buttonAlbum.setOnClickListener { frag.clickAlbum() }
        frag.viewfinderView.setLabelText("请扫描二维码")
    }
}